/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package allthemoneyflowers.controllers;

import allthemoneyflowers.model.Login;
import allthemoneyflowers.model.User;
import static java.rmi.Naming.list;
import java.util.ArrayList;
import static java.util.Collections.list;


/**
 *
 * @author wolf
 */

/*O CONTROLLER THA PERNEI TO ArrayList KAI TA TO SIGRINEI ME TO ANTIKEIMENO Lonin POU EDWSE O XRHSTHS
SE PERIPTWSH POU EINAI TRUE BAZEI TIS TIMES APO TO Login SE ENA NEW ANTIKEIMENO USER KAI EPISTREFEI TON User
ALLIWS EPISTREFEI MINIMA LATHOUS
SOS!!KAI USERNAME NA EINAI SWSTO KAI PASSWORD!!*/
public class LoginController {
    private  User user = new User();
        
    public User userSearch(Login login,ArrayList<User> userList) {
        if (userList!=null)//Elenxos an einai keni i lista userList
        {
            if(login!=null)//Elenxos an einai keno to login antikeimeno
            {
                //System.out.printf(login.getUsernameLogin());
                for(int i = 0; i < userList.size(); i++)//prospelasi tis listas userList
                {
                    //System.out.printf(login.getPasswordLogin()+login.getUsernameLogin());
                        if(userList.get(i).getPassword() == login.getPasswordLogin() //ERROR o User dn pernei tis times tou
                           && userList.get(i).getUsername() == login.getUsernameLogin())//Lathos elenxos!!
                        {
                            user.setPassword(userList.get(i).getPassword());
                            user.setUsername(userList.get(i).getUsername());
                            user.setUserID(userList.get(i).getUserID());
                            //System.out.printf(userList.get(i).getUsername());
                            //return user;                        
                        }    
                }
            }
            else{
                System.out.printf("To login einai keno");
            }
        }
        else {
            System.out.printf("H lista einai keni");
        }
        return user;
     
    }
    
    
    
    
    
    
   
    
}
